Check out this article on various visualizations that can be made with Plottly express: Link
| Objective | Complete |
|---|---|
| Build heatmaps and geographic maps using plotly | |
| Add animations to maps |
density heatmap is a two dimensional histogram# Create a density heatmap of tips dataset using plotly function density_heatmap
fig = px.density_heatmap(tips_dataset,
x = "total_bill",
y = "tip")
fig.show()plotly express also has the built-in capabilities to put data on a US map by using an extra parameter called scope Not all data fits nicely on a world map or a U.S. map; perhaps we want to show things at a more granular level, like county or district or even neighborhood level
If this is the case, we might need to get a ‘geoJSON’ file to add to our map
A ‘geoJSON’ contains all the border lines for the areas we want our map to be divided into
You can generally find a ‘geoJSON’ already available for what you are looking to map, but if not, there are plenty of generators that are free online
locations parameter is set to the location column in our dataframe and the featureidkey parameter is set to the feature key in the JSON which holds the matching granularityelection_dataset = px.data.election()
geojson = px.data.election_geojson()
fig = px.choropleth(election_dataset,
geojson=geojson,color="Bergeron",
locations="district",
featureidkey="properties.district",
projection="mercator")
fig.update_geos(fitbounds="locations",
visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()| Objective | Complete |
|---|---|
| Build heatmaps and geographic maps using plotly |
✔ |
| Add animations to maps |
animation_frameanimation_groupfig = px.choropleth(gapminder_dataset,
locations="iso_alpha",
color="lifeExp",
hover_name="country",
animation_frame="year",
range_color=[20,80])
fig.show()
You are now ready to try tasks 9-14 in the Exercise for this topic
| Objective | Complete |
|---|---|
| Build heatmaps and geographic maps using plotly |
✔ |
| Add animations to maps |
✔ |
In this part of the course, we have covered:
plotly expressplotly express